//package ;
//
//import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
//import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;
//import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
//import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;
//import org.springframework.util.CollectionUtils;
//
//import java.util.ArrayList;
//import java.util.Collection;
//import java.util.Date;
//import java.util.List;
//
//public class MonthDayShardingAlgorithm implements PreciseShardingAlgorithm<Date>, RangeShardingAlgorithm<Date> {
//
//    @Override
//    public String doSharding(Collection<String> availableTargetNames
//            , PreciseShardingValue<Date> shardingValue) {
//        int month = DateUtil.month(shardingValue.getValue());
//        int day = DateUtil.day(shardingValue.getValue());
//        String tableName = shardingValue.getLogicTableName() + "_" + month + "_" + day;
//        if (availableTargetNames.contains(tableName)) {
//            return tableName;
//        }
//        throw new UnsupportedOperationException(String.format(
//                "route %s unsupported, check sharding config"
//                , tableName
//        ));
//    }
//
//    @Override
//    public Collection<String> doSharding(Collection<String> availableTargetNames
//            , RangeShardingValue<Date> shardingValue) {
//        List<String> tableNameRange = new ArrayList<>();
//        int lowerMonth = DateUtil.month(shardingValue.getValueRange().lowerEndpoint());
//        int lowerDay = DateUtil.day(shardingValue.getValueRange().lowerEndpoint());
//        int upperMonth = DateUtil.month(shardingValue.getValueRange().upperEndpoint());
//        int upperDay = DateUtil.day(shardingValue.getValueRange().upperEndpoint());
//        for (int month = lowerMonth; month <= upperMonth; ++month) {
//            for (int day = lowerDay; day <= upperDay; ++day) {
//                String tableName = shardingValue.getLogicTableName() + "_" + month + "_" + day;
//                if (availableTargetNames.contains(tableName)) {
//                    tableNameRange.add(tableName);
//                }
//            }
//        }
//        if (CollectionUtils.isEmpty(tableNameRange)) {
//            throw new UnsupportedOperationException(String.format(
//                    "route %s.%s - %s.%s unsupported, check sharding config"
//                    , lowerMonth, lowerDay, upperMonth, upperDay
//            ));
//        }
//        return tableNameRange;
//    }
//}
//
//
